home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_348 / samp / tosamp.asm < prev    next >
Assembly Source File  |  1992-05-06  |  22KB  |  869 lines

  1. ; Assembled with Innovatronic's CAPE assembler with the SMALLOBJ directive.
  2. ; (i.e. PC relative code). For other assemblers, uncomment the section
  3. ; directive before the data section.
  4. ; Link as follows:
  5. ; Blink SmallStart.o ToSAMP.o small.lib NODEBUG to ToSAMP
  6. ; where SmallStart.o is the startup code included with this program and
  7. ; small.lib is Bryce Nesbitt's amiga.lib.
  8. ; For Manx,
  9. ; as -cd -o ToSAMP ManxStartUp.o ToSAMP.o -lcl32
  10. ;
  11. ; This example uses R.J. Mical's FileIO requester in a special library form
  12. ; prepared by dissidents as well as the instype.library
  13.  
  14.     SMALLOBJ
  15.     OBJFILE  "rad:ToSamp.o"
  16.     OPTIMON
  17.     ADDSYM
  18.  
  19.     INCLUDE    "rad:FileIO.i" ;requires RJ Mical's FileIO in library form
  20.  
  21.     SECTION    ToSampCode,CODE
  22.  
  23. _LVOGetInsType    equ -30
  24.  
  25.     XREF    _DOSBase,_SysBase ;from StartUp code
  26.  
  27.     XREF    _LVOOpenLibrary,_LVOCloseLibrary,_LVOOpenWindow,_LVOCloseWindow
  28.     XREF    _LVOAllocMem,_LVOFreeMem
  29.     XREF    _LVOGetMsg,_LVOReplyMsg,_LVOWait,_LVOWaitPort
  30.     XREF    _LVOPrintIText,_LVODrawImage
  31.     XREF    _LVOMove,_LVOText,_LVOSetAPen
  32.     XREF    _LVOOpen,_LVORead,_LVOWrite,_LVOClose,_LVODelay
  33.     XREF    _LVOLock,_LVOUnLock,_LVOExamine,_LVODeleteFile
  34.  
  35. MODE_OLDFILE equ 1005
  36. MODE_NEWFILE equ 1006
  37. LIB_VERSION  equ 33
  38.  
  39. blank:
  40.         moveq        #17-1,d2
  41.         moveq        #10,d3
  42.         moveq        #10,d4
  43. mG        lea        SPACES,a4
  44.         moveq        #26,d0
  45.         add.w        d3,d4
  46.         move.w    d4,d1
  47.         bsr.s        print_msg
  48.         Dbra        d2,mG
  49.         rts
  50.  
  51.   XDEF print_msg  ;string passed in a4, x in d0, y in d1
  52. print_msg:
  53.         movea.l    RastPort,a2
  54.         movea.l    a2,a1
  55.         movea.l    _GfxBase,a6
  56.         jsr        _LVOMove(a6)
  57.         movea.l    a4,a0
  58. len    move.b    (a4)+,d0
  59.         bne.s        len
  60.         move.l    a4,d0
  61.         subq.l    #1,d0
  62.         sub.l        a0,d0            ;length of string
  63.         movea.l    a2,a1            ;RastPort
  64.         jmp        _LVOText(a6)
  65.  
  66.     XDEF    print_directions
  67. print_directions:
  68.         lea        Directions,a4
  69.         lea        Positions,a5
  70.         moveq        #10-1,d2
  71.         moveq        #10,d3
  72.         moveq        #10,d4
  73. mg        move.w    (a5)+,d0
  74.         add.w        d3,d4
  75.         move.w    d4,d1
  76.         bsr.s        print_msg  ;returns end of msg (beginning of next string)
  77.         Dbra        d2,mg
  78.         rts
  79.  
  80. Positions dc.w 38,28,38,26,30,39,29,24,30,84
  81.  
  82.    XDEF _main
  83. _main:
  84. ;---Open Gfx Library
  85.         movea.l    _SysBase,a6
  86.         moveq        #LIB_VERSION,d0
  87.         lea        GfxName,a1
  88.         jsr        _LVOOpenLibrary(a6)
  89.         move.l    d0,_GfxBase
  90.         bne.s        xx
  91.         rts
  92. ;---Open Intuition
  93. xx        moveq        #LIB_VERSION,d0
  94.         lea        IntuitionName,a1
  95.         jsr        _LVOOpenLibrary(a6)
  96.         move.l    d0,_IntuitionBase
  97.         beq        clG
  98. ;---Open the main window
  99.         lea        newWindow,a0
  100.         move.l    a6,-(sp)
  101.         movea.l    d0,a6
  102.         jsr        _LVOOpenWindow(a6)
  103.         movea.l    (sp)+,a6
  104.         move.l    d0,WindowPtr
  105.         beq        clI
  106.         move.l    d0,a0
  107.         move.l    50(a0),RastPort
  108. ;---Open the FileIO (requester) library
  109.         moveq        #1,d0            ;version #1
  110.         lea        RequesterName,a1
  111.         jsr        _LVOOpenLibrary(a6)
  112.         move.l    d0,_RequesterBase
  113.         bne.s        gotit
  114.         ;---error
  115.         lea        FileReqErr,a4
  116.         moveq        #5,d0
  117.         moveq        #75,d1
  118.         bsr        print_msg
  119.         moveq        #100,d1
  120.         movea.l    _DOSBase,a6
  121.         jsr        _LVODelay(a6)
  122.         bra        clW
  123. ;===================Get the FileIO Structure========================
  124. gotit    movea.l    d0,a6
  125.         jsr        _LVOGetFileIO(a6)
  126.         move.l    d0,FileIO
  127.         bne.s        gotIO
  128.         lea        IOerR,a4
  129.         moveq        #5,d0
  130.         moveq        #75,d1
  131.         bsr        print_msg
  132.         moveq        #100,d1
  133.         movea.l    _DOSBase,a6
  134.         jsr        _LVODelay(a6)
  135.         bra        clF
  136.   ;---Set up info file suppression
  137. gotIO    movea.l    d0,a0
  138.         Bset.b    #INFO_SUPPRESS,1(a0)  ;INFO_SUPPRESS ON
  139.   ;--Set up the XY co-ordinates of where the requester will open
  140.   ; If we used DoFileIOWindow(), we wouldn't need to set co-ordinates.
  141.         moveq        #6,d0
  142.         move.w    d0,FILEIO_X(a0)  ;x position
  143.         moveq        #11,d0
  144.         move.w    d0,FILEIO_Y(a0)  ;y position
  145.     ;---Setup buffer for path name
  146.         lea        _BUFFER2,a1
  147.         move.l    a1,FILEIO_BUFFER(a0)
  148.     ;---Setup Pens and DrawMode
  149.         moveq        #1,d0
  150.         move.b    d0,FILEIO_DRAWMODE(a0)
  151.         move.b    d0,FILEIO_PENA(a0)
  152. ;====Create a mask of the Window's UserPort's mp_Sigbit=====
  153.         movea.l    WindowPtr,a3
  154.         movea.l    86(a3),a0
  155.         move.b    15(a0),d0
  156.         moveq        #0,d7
  157.         Bset.l    d0,d7
  158. ;----Print out Directions
  159. START    bsr        print_directions
  160. ;********************** MAIN LOOP ******************************
  161. ;=====Get the message that arrived at our UserPort====
  162. E4        movea.l    86(a3),a0
  163.         movea.l    _SysBase,a6
  164.         jsr        _LVOGetMsg(a6)
  165.         move.l    d0,d1
  166.         bne.s        E7
  167. ;===Check if we are ready to exit the program=====
  168.         Btst.b    #0,Quit
  169.         beq        delFile
  170. ;===Wait for a message sent to our Window (from Intuition)===
  171.         move.l    d7,d0
  172.         jsr        _LVOWait(a6)
  173.         bra.s        E4
  174. ;====Copy all the info we want from the IntuiMessage====
  175. E7        movea.l    d0,a1
  176.         lea        20(a1),a0  ;get the address of the first field to copy.
  177.         move.l    (a0)+,d6   ;Copy the Class field to d6
  178.         move.w    (a0)+,d5   ;Copy the Code field to d5
  179.         move.w    (a0)+,d4   ;Copy the qualifier field to d4
  180.         movea.l    (a0)+,a2   ;Copy the IAddress field to a2
  181.         move.w    (a0)+,d3   ;Copy MouseX position to d3
  182.         move.w    (a0)+,d2   ;Copy MouseY position to d2
  183. ;====Now reply to the message so Intuition can dispose of it
  184. E8        ;Address of the message is in a1.
  185.         jsr        _LVOReplyMsg(a6)
  186. ;========switch (class)=========
  187.         Bclr.l    #3,d6  ;MOUSEBUTTONS
  188.         bne.s        GADG
  189.         Bclr.l    #9,d6  ;CLOSEWINDOW
  190.         beq.s        E4
  191. ;=========case CLOSEWINDOW:============
  192. CW        Bclr.b    #0,Quit
  193.         bra.s        E4
  194. ;=========case MOUSEBUTTONS:===========
  195. ;---Make sure that it's an UP select if MOUSEBUTTONS
  196. GADG    subi.b    #$68,d5
  197.         beq        E4     ;ignore down
  198.     ;---get the user's filename and load the 8SVX file
  199. E2        bsr        load_8SVX
  200.         subq.b    #1,d0
  201.         bne.s        Cerr
  202.     ;---Convert the file to SAMP and save
  203.         bsr        convert_8SVX
  204.         subq.b    #1,d0
  205.         bne.s        Cerr
  206.         ;---Indicate a successful conversion
  207.         lea        Success,a4
  208.     ;---delete the 8SVX conversion buffer if it exists
  209. Cerr    bsr        free_data
  210.         move.l    a4,-(sp)
  211.         bsr        blank
  212.     ;---Print the returned error message
  213.         movea.l    _RequesterBase,a6
  214.         movea.l    a3,a0
  215.         move.l    (sp)+,d0
  216.         jsr        _LVOAutoMessage(a6)
  217.         bra        START
  218. ;******************** Exit the Program *********************
  219.      ;If the pointer to FileIO was NULL, then
  220.      ;ReleaseFileIO just returns, so it's safe to
  221.      ;always release any return value of GetFileIO.
  222. delFile:
  223.         movea.l    FileIO,a1
  224.         movea.l    _RequesterBase,a6
  225.         jsr        _LVOReleaseFileIO(a6)
  226.     ;---Close the graphics lib
  227. clF    movea.l    _RequesterBase,a1
  228.         movea.l    _SysBase,a6
  229.         jsr        _LVOCloseLibrary(a6)
  230.     ;---Close the window
  231. clW    movea.l    WindowPtr,a0
  232.         movea.l    _IntuitionBase,a6
  233.         jsr        _LVOCloseWindow(a6)
  234.     ;---Close the Intuition Lib
  235. clI    movea.l    _SysBase,a6
  236.         movea.l    _IntuitionBase,a1
  237.         jsr        _LVOCloseLibrary(a6)
  238.     ;---Close the graphics lib
  239. clG    movea.l    _GfxBase,a1
  240.         jmp        _LVOCloseLibrary(a6)
  241.  
  242.     XDEF    load_8SVX
  243. load_8SVX:
  244.         movem.l    d2/d3/d4/d5,-(sp)
  245.     ;---Get the user's filename via the FileIO requester
  246.         movea.l    WindowPtr,a1
  247.         movea.l    FileIO,a0
  248.         movea.l    _RequesterBase,a6
  249.         jsr        _LVODoFileIO(a6)
  250.         move.l    d0,d1
  251.         bne.s        L92    ;If 0, must have been an error
  252.         lea        LibErr,a4
  253. outL    movem.l    (sp)+,d2/d3/d4/d5
  254.         rts
  255. L92    addq.l    #1,d0
  256.         bne.s        L90
  257.     ;---If -1, user must have selected CANCEL
  258.         lea        Cancel,a4
  259.         bra.s        outL
  260.     ;---Get the File's Size
  261. L90    movea.l    FileIO,a0
  262.         move.l    FILEIO_FILESIZE(a0),d0
  263.         move.l    d0,FileSize
  264.         bne.s        L89
  265.         ;---If size = 0, then this file must not exist (in this directory)
  266. L95    lea        CantFind,a4
  267.         bra.s        outL
  268.     ;---get a conversion buffer to copy in the entire 8SVX file
  269. L89    movea.l    _SysBase,a6
  270.         moveq        #1,d1
  271.         jsr        _LVOAllocMem(a6)
  272.         move.l    d0,_8SVXData   ;the address of conversion buffer
  273.         bne.s        L93
  274.         move.l    d0,FileSize    ;size of conversion buffer
  275.         lea        NoMem,a4
  276.         bra.s        outL
  277.     ;---Open the file
  278. L93    moveq        #0,d2
  279.         move.w    #MODE_OLDFILE,d2
  280.         lea        _BUFFER2,a0
  281.         move.l    a0,d1
  282.         movea.l    _DOSBase,a6
  283.         jsr        _LVOOpen(a6)
  284.         move.l    d0,d4
  285.         beq.s        L95
  286.     ;---Make sure that this is an 8SVX file
  287.         moveq        #20,d3     ;read the first 20 bytes
  288.         move.l    _8SVXData,d2
  289.         move.l    d4,d1
  290.         jsr        _LVORead(a6)
  291.         sub.l        d0,d3
  292.         bne.s        CloseR
  293.         movea.l    _8SVXData,a0
  294.         addq.l    #8,a0
  295.         move.l    _8SVX,d0
  296.         sub.l        (a0),d0
  297.         beq.s        readin
  298.         ;---Not 8SVX
  299. NotIFF:
  300.         move.l    d4,d1
  301.         jsr        _LVOClose(a6)
  302.         moveq        #0,d0
  303.         lea        Not8SVX,a4
  304.         bra        outL
  305.     ;---Read in the rest of the file (starting with VHDR's oneShotHiSamples)
  306. readin:
  307.         move.l    FileSize,d3
  308.         moveq        #20,d0
  309.         sub.l        d0,d3
  310.         move.l    _8SVXData,d2 
  311.         move.l    d4,d1
  312.         jsr        _LVORead(a6)
  313.         sub.l        d0,d3
  314. CloseR:
  315.         move.l    d4,d1
  316.         jsr        _LVOClose(a6)
  317.         moveq        #1,d0
  318.         move.l    d3,d1
  319.         beq        outL
  320.         lea        ReadErr,a4
  321.         moveq        #0,d0
  322.         bra        outL
  323.  
  324. ; This frees the conversion buffer when we are done with it, and also
  325. ; re-initializes the data section for converting another file.
  326.  
  327.     XDEF    free_data
  328. free_data:
  329.         lea        _8SVXData,a0
  330.         move.l    (a0),d0
  331.         beq.s        no8D
  332.         clr.l        (a0)+
  333.         movea.l    d0,a1
  334.         move.l    (a0),d0  ;FileSize
  335.         movea.l    _SysBase,a6
  336.         jsr        _LVOFreeMem(a6)
  337. no8D    move.l    #518+8+8+4,sizeOfChunks
  338.         clr.l        ATAKptr
  339.         clr.l        RLSEptr
  340.         clr.l        sizeOfBODY
  341.         clr.l        nameSize
  342.         moveq        #-1,d0
  343.         move.w    d0,midiSampNum
  344.         lea        playMap,a1
  345.         moveq        #128-1,d0
  346. cpm    clr.l        (a1)+
  347.         dbra        d0,cpm
  348.         rts
  349.  
  350.     XDEF    divide
  351.     ;This routine divides 2 LONGS passed in d0 and d1.
  352.     ;d0 = d0/d1 with d2 = the remainder.
  353. divide:
  354.     moveq        #0,d2
  355.     moveq        #31,d3
  356. _1    asl.l        #1,d0
  357.     roxl.l    #1,d2
  358.     cmp.l        d1,d2
  359.     bcs.s        _2
  360.     sub.l        d1,d2
  361.     addq.l    #1,d0
  362. _2    Dbra        d3,_1
  363.     rts
  364.  
  365.     XDEF    convert_8SVX
  366. convert_8SVX:
  367.         movem.l    d2/d3/d4/d5/a3/a4,-(sp)
  368.     ;---Make the SAMP playMap. Assign each interpolation an octave in the map
  369.     ;   The numOfChans in the playMap will be 4.
  370.         movea.l    _8SVXData,a4
  371.         lea        playMap,a1
  372.         moveq        #0,d0
  373.         move.b    14(a4),d0    ;the number of octaves in the 8SVX file
  374.         beq        CCC
  375.     ;---limit to 10 octaves of the 8SVX file (numbered 1 to 10)
  376.         moveq        #10,d1
  377.         cmp.b        d1,d0
  378.         bls.s        okOT
  379.         move.b    d1,d0
  380. okOT    move.b    d0,numOfWaves
  381. nto    moveq        #12-1,d1        ;1 octave of notes
  382. octt    move.b    d0,(a1)+
  383.         move.b    d0,(a1)+
  384.         move.b    d0,(a1)+
  385.         move.b    d0,(a1)+
  386.         Dbra        d1,octt
  387.         subq.b    #1,d0
  388.         bne.s        nto
  389.     ;---Store the sampleRate
  390.         move.w    12(a4),d1    ;samplesPerSec
  391.         beq.s        def
  392.         move.l    d1,sampleRate
  393.         ;---calculate samplePeriod
  394.         move.l    #1000000000,d0 ;in nanoseconds
  395.         bsr.s        divide
  396.         move.l    d0,samplePeriod
  397. def    lea        20(a4),a0      ;the chunk after VHDR
  398. ;================PROCESS AN 8SVX CHUNK================
  399. nChk    bsr        DoWeWantIt
  400.         beq        BodyHandler ;the last chunk in 8SVX
  401.         subq.b    #1,d0
  402.         beq.s        DoName
  403.         subq.b    #1,d0
  404.         beq        DoATAK
  405.         subq.b    #1,d0
  406.         beq        DoRLSE
  407.     ;---Throw away this chunk (i.e. ANNO, AUTH)
  408. thrw    move.l    4(a0),d0    ;chunk size
  409.         Btst.l    #0,d0
  410.         beq.s        even
  411.         addq.l    #1,d0
  412. even    addq.l    #8,a0
  413.         adda.l    d0,a0        ;skip to the end of the chunk
  414.         bra.s        nChk
  415. ;--'NAME': Copy the "Master" name to name buffer and count # of chars
  416. ;  including NULL (+1 to append the wave number). Calculate the final
  417. ;  resulting chunk size. Make sure that the name is an even # of bytes.
  418. DoName:
  419.         lea        name,a1
  420.         moveq        #19-1,d0    ;copy 19 chars (including NULL) Max
  421.         movea.l    a0,a3
  422.         addq.l    #8,a3
  423.         move.l    a1,d1
  424. cnm    move.b    (a3)+,(a1)+
  425.         Dbeq        d0,cnm
  426.         move.l    a1,d0
  427.         clr.b        -(a1)
  428.         sub.l        d1,d0        ;length of 1 wave name counting NULL
  429.         addq.l    #1,d0        ;allow for appending the wave (octave) number
  430.         Btst.l    #0,d0
  431.         beq.s        EVEN
  432.         addq.l    #1,d0
  433.         move.b    #' ',(a1)+
  434. EVEN    move.l    a1,nameNULL
  435.         moveq        #0,d1
  436.         move.b    numOfWaves,d1
  437.         mulu.w    d1,d0     
  438.         move.l    d0,nameSize
  439.         bra.s        thrw
  440. ;---Note the address and size (bytes) of the ATAK chunk. We'll copy it to
  441. ;   disc verbatim...once for each wave.
  442. DoATAK:
  443.         movea.l    a0,a3
  444.         addq.l    #4,a3
  445.         move.l    (a3)+,d0
  446.         move.l    d0,sizeOfATAK ;This should always be even.
  447.         move.l    a3,ATAKptr    ;addr of EGpoints[]
  448.     ;---add the (size of chunk) x numOfWaves to sizeOfBODY
  449. sze    moveq        #0,d1
  450.         move.b    numOfWaves,d1
  451.         mulu.w    d1,d0        ;should actually be a LONG multiply just in case!
  452.         add.l        d0,sizeOfBODY
  453.         bra.s        thrw
  454. DoRLSE:
  455.         movea.l    a0,a3
  456.         addq.l    #4,a3
  457.         move.l    (a3)+,d0
  458.         move.l    d0,sizeOfRLSE
  459.         move.l    a3,RLSEptr  ;addr of EGPoints[]
  460.         bra.s        sze
  461. ;================== BODY ==========================
  462. BodyHandler:
  463. ;Calculate size of BODY and total size of all chunks
  464.         addq.l    #8,a0            ;get beginning of sample data
  465.         lea        SampleInfo0,a3
  466.         move.b    numOfWaves,d0
  467.         subq.b    #1,d0
  468.         move.l    (a4),d4        ;oneShotHiSamples
  469.         move.l    4(a4),d5        ;repeatHiSamples
  470.         move.l    a0,(a3)+
  471.         move.l    d4,(a3)+
  472.         move.l    d4,d1
  473.         add.l        d5,d1            ;total size of this wave
  474.         move.l    d1,d2            ;store sum of all wave sizes in d2
  475.         moveq        #80,d3        ;80 byte waveHeader in BODY for each wave
  476.         bra.s        _1o
  477.     ;---Store one wave's waveHeader
  478. agns    move.l    a0,(a3)+        ;start address of sample data
  479.         lsl.l        #1,d4            ;2x oneShot size
  480.         move.l    d4,(a3)+        ;size of oneShot (also loopStart offset)
  481.         lsl.l        #1,d5            ;size of loop portion
  482.         move.l    d5,d1
  483.         add.l        d4,d1
  484.         add.l        d1,d2
  485. _1o    add.l        d3,d2            ;add size of waveHeader
  486.         move.l    d1,(a3)+        ;loopEnd offset (also this wave's waveSize)
  487.         adda.l    d1,a0            ;next wave
  488.         Dbra        d0,agns
  489.         add.l        d2,sizeOfBODY
  490.     ;---calculate the total size of ALL chunks in the SAMP file
  491.         move.l    nameSize,d0
  492.         beq.s        noNh
  493.         addq.l    #8,d0            ;add 8 bytes for NAME header
  494. noNh    add.l        sizeOfBODY,d0
  495.         add.l        d0,sizeOfChunks
  496. ;============== ASK THE USER TO DETERMINE THE INSTRUMENT TYPE =============
  497.         lea        InsTypeName,a1
  498.         movea.l    _SysBase,a6
  499.         moveq        #0,d0
  500.         jsr        _LVOOpenLibrary(a6)
  501.         move.l    d0,d2
  502.         beq.s        sunk
  503.         movea.l    d0,a6
  504.         movea.l    ScreenPtr,a1
  505.         jsr        _LVOGetInsType(a6)
  506.         move.w    d0,d2
  507.         bpl.s        gtyp
  508.         moveq        #0,d2
  509. gtyp    movea.l    a6,a1
  510.         movea.l    _SysBase,a6
  511.         jsr        _LVOCloseLibrary(a6)
  512. sunk    move.b    d2,Itype
  513. ;======================= GET NEW FILENAME =====================
  514.     ;---Does user want to save the same Filename with .SAMP extention?
  515. unkn    lea        _BUFFER2,a0
  516.         lea        SAMPext,a1
  517.         movem.l    a2/a3,-(sp)
  518.         bsr        appendstr
  519.         movea.l    _RequesterBase,a6
  520.         movea.l    WindowPtr,a0
  521.         lea        _BUFFER2,a2
  522.         lea        Same,a1
  523.         suba.l    a3,a3
  524.         jsr        _LVOAutoPrompt3(a6)
  525.         movem.l    (sp)+,a2/a3
  526.         move.b    d0,d1
  527.         bne.s        sav
  528.     ;---Get a new name via the FileIO lib
  529.     ;---DoFileIO(FileIO, window)
  530.         movea.l    WindowPtr,a1
  531.         movea.l    FileIO,a0
  532.         jsr        _LVODoFileIO(a6)
  533.         addq.l    #1,d0
  534.         bne.s        sav
  535.         ;If -1, user must have selected CANCEL. Abort the Conversion.
  536.         lea        Cancel,a4
  537. outS    movem.l    (sp)+,d2/d3/d4/d5/a3/a4
  538.         rts
  539. ;======================== WRITE THE SAMP FILE ===================
  540.     ;---Create this file
  541. sav    lea        _BUFFER2,a0
  542.         movea.l    _DOSBase,a6
  543.         move.l    a0,d1
  544.         moveq        #0,d2
  545.         move.w    #MODE_NEWFILE,d2
  546.         jsr        _LVOOpen(a6)
  547.         move.l    d0,d4
  548.         bne.s        fh
  549.     ;---error
  550. CCC    lea        CantCreate,a4
  551.         bra.s        outS
  552.     ;---Write SAMP and MHDR chunks, and the 8 byte NAME header (if it exists)
  553. fh        moveq        #0,d3
  554.         move.w    #518+8+8+4,d3
  555.         move.l    nameSize,d2
  556.         beq.s        nNH
  557.         addq.l    #8,d3
  558. nNH    lea        SAMPFORM,a0
  559.         move.l    a0,d2
  560.         move.l    d4,d1
  561.         jsr        _LVOWrite(a6)
  562.         sub.l        d0,d3
  563.         beq.s        wwOK
  564.     ;---WRITE error
  565. WE        move.l    d4,d1
  566.         jsr        _LVOClose(a6)
  567.         lea        _BUFFER2,a0
  568.         move.l    a0,d1
  569.         jsr        _LVODeleteFile(a6)
  570.         lea        WriteErr,a4
  571.         moveq        #0,d0
  572.         bra.s        outS
  573.     ;---Write the NAME chunk (if nameSize is not 0)
  574. wwOK    move.l    nameSize,d0
  575.         beq.s        WrOK
  576.         moveq        #0,d5
  577.         move.b    numOfWaves,d5
  578.         subq.b    #1,d5
  579.     ;---append the wave number each time that we write out the name
  580. nnnn    movea.l    nameNULL,a0
  581.         move.b    d5,d1
  582.         addi.b    #'0',d1
  583.         move.b    d1,(a0)+
  584.         clr.b        (a0)+
  585.         lea        name,a1
  586.         move.l    a1,d2
  587.         suba.l    a1,a0
  588.         move.l    a0,d3
  589.         move.l    d4,d1
  590.         jsr        _LVOWrite(a6)
  591.         sub.l        d0,d3
  592.         bne.s        WE
  593.         Dbra        d5,nnnn
  594.     ;---Save the 8 byte BODY header
  595. WrOK    lea        BODY,a0
  596.         moveq        #8,d3
  597.         move.l    a0,d2
  598.         move.l    d4,d1
  599.         jsr        _LVOWrite(a6)
  600.         sub.l        d0,d3
  601.         bne.s        WE
  602. ;********** SAVE WAVES (80 byte waveHeader and data for each wave) *********
  603.         lea      SampleInfo0,a3
  604.         moveq    #0,d5
  605.         move.b   numOfWaves,d5
  606.         moveq    #12,d0
  607.         mulu.w   d5,d0
  608.         addq.b   #6,d0
  609.         move.b   d0,rootNote  ;set the rootNote for the highest octave
  610.         subq.b   #1,d5
  611. ;================ SAVE 1 WAVE =====================
  612. savesam:
  613.     ;---Store BODY parameters for this wave
  614.         lea      waveSize,a0
  615.         move.l   8(a3),(a0)+ ;store loopEnd in waveSize
  616.         addq.w   #1,(a0)     ;inc midiSampNum
  617.         addq.l   #8,a0
  618.         addq.l   #4,a0
  619.         move.l   4(a3),(a0)+ ;store loopStart
  620.         move.l   8(a3),(a0)+ ;store loopEnd
  621.         subi.b   #12,(a0)    ;dec to middle of previous octave
  622.     ;---Write the 80 byte waveHeader
  623.         moveq    #80,d3
  624.         lea      waveHeader,a0
  625.         move.l   a0,d2
  626.         move.l   d4,d1
  627.         jsr      _LVOWrite(a6)
  628.         sub.l    d0,d3
  629.         bne      WE
  630.     ;---see if there are ATAK EgPoints to write
  631.         move.l   ATAKptr,d2
  632.         beq.s    noAT
  633.         move.l   sizeOfATAK,d3
  634.         move.l   d4,d1
  635.         jsr      _LVOWrite(a6)
  636.         sub.l    d0,d3
  637.         bne      WE
  638.     ;---Write any RLSE EgPoints
  639. noAT    move.l   RLSEptr,d2
  640.         beq.s    noRT
  641.         move.l   sizeOfRLSE,d3
  642.         move.l   d4,d1
  643.         jsr      _LVOWrite(a6)
  644.         sub.l    d0,d3
  645.         bne      WE
  646.     ;---write the wave's data
  647. noRT    move.l   (a3)+,d2
  648.         move.l   d4,d1
  649.         addq.l   #4,a3
  650.         move.l   (a3)+,d3
  651.         jsr      _LVOWrite(a6)
  652.         sub.l    d0,d3
  653.         bne      WE
  654.     ;---do the next wave
  655.         Dbra     d5,savesam
  656.     ;---close the file and return success
  657.         move.l   d4,d1
  658.         jsr      _LVOClose(a6)
  659.         moveq    #1,d0
  660.         bra      outS
  661.  
  662.     XDEF    appendstr
  663. appendstr:
  664.         move.b    (a0)+,d1
  665.         bne.s        appendstr
  666.         subq.l    #1,a0
  667. appp    move.b    (a1)+,(a0)+
  668.         bne.s        appp
  669.         rts
  670.  
  671.    XDEF DoWeWantIt
  672. DoWeWantIt:
  673.         move.l    (a0),d0
  674.         cmp.l        NAME,d0
  675.         beq.s        itsNAME
  676.         cmp.l        ATAK,d0
  677.         beq.s        itsATAK
  678.         cmp.l        RLSE,d0
  679.         beq.s        itsRLSE
  680.         sub.l        BODY,d0
  681.         bne.s        unKn
  682.         rts
  683. itsNAME:
  684.         moveq        #1,d0
  685.         rts
  686. itsATAK:
  687.         moveq        #2,d0
  688.         rts
  689. itsRLSE:
  690.         moveq        #3,d0
  691.         rts
  692. unKn    moveq        #-1,d0
  693.         rts
  694.  
  695.     ; SECTION ToSAMPData,Data   ;UnComment if not using CAPE
  696.  
  697.    XDEF   newWindow
  698. newWindow:
  699.             dc.w   0,0
  700.             dc.w   640,200
  701.             dc.b   0,1
  702.  ;IDCMP = MOUSEBUTTONS|CLOSEWINDOW|RAWKEY
  703.             dc.l   $608
  704. ;WindowFlags = WINDOWCLOSE|WINDOWDEPTH|SMART_REFRESH|ACTIVATE (no FOLLOWMOUSE
  705. ;allowed as that messes up the requester when using DoFileIO(). If you need
  706. ;FOLLOWMOUSE, then use DoFileIOWindow() to open the req in its own window.)
  707.             dc.l   $100C
  708.             dc.l   0
  709.             dc.l   0
  710.             dc.l   WINTITLE
  711. ScreenPtr dc.l   0
  712.             dc.l   0
  713.             dc.w   96,30
  714.             dc.w   320,200
  715.             dc.w   1         ;WBENCHSCREEN
  716.  
  717. TextAttr:        ;Topaz 8 is a ROM font so doesn't need to be opened
  718.     dc.l    FONTNAME
  719.     dc.w    8        ;TOPAZ_EIGHTY
  720.     dc.b    0,0
  721.  
  722.     XDEF    _GfxBase,_IntuitionBase,_RequesterBase,WindowPtr,RastPort
  723.     XDEF    _8SVXData,FileSize,FileIO,RequesterName,nameNULL,name,nameSize,NAME
  724.  
  725. _GfxBase            dc.l  0
  726. _IntuitionBase    dc.l  0
  727. _RequesterBase    dc.l  0
  728. WindowPtr        dc.l  0
  729. RastPort            dc.l  0
  730. _8SVXData        dc.l  0
  731. FileSize            dc.l  0
  732. FileIO            dc.l  0
  733.  
  734. ATAK            dc.b    'ATAK'
  735. RLSE            dc.b    'RLSE'
  736. _8SVX            dc.b    '8SVXVHDR'
  737. nameNULL        dc.l    name
  738. name            ds.b    20        ;buffer for the NAME chunk
  739.  
  740.     XDEF SAMP,sizeOfChunks,MHDR,sizeOfMHDR,playMap,numOfWaves,BODY,sizeOfBODY
  741.     XDEF name,waveSize,midiSampNum,loopType,sampleRate,samplePeriod
  742.     XDEF loopStartPoint,loopEndPoint,rootNote,sizeOfATAK,ATAKptr,RLSEptr
  743.     XDEF sizeOfRLSE,SampleInfo0,sizeOfFATK
  744.  
  745. ;===================== SAMP PORTION ==========================
  746. SAMPFORM            dc.b    'FORM'
  747. sizeOfChunks    dc.l    518+8+8+4    ;MHDR size + MHDR Header + BODY Header (add
  748.                                             ;sizeOfBODY, nameSize, other chunks size)
  749. SAMP                dc.b    'SAMP'
  750. ;------------------------------
  751. MHDR                dc.b    'MHDR'
  752. sizeOfMHDR        dc.l    518
  753. numOfWaves        dc.b    0
  754. sampleFormat    dc.b    8
  755. Flags                dc.b    0
  756. playMode            dc.b    1        ;MULTI default
  757. numOfChans        dc.b    4        ;each midi note has 4 bytes in the playMap
  758. mhdrPad            dc.b    0
  759. playMap            ds.l    128    ;4 bytes for each of 128 midi notes
  760. NAME                dc.b    'NAME'
  761. nameSize            dc.l    0
  762.  
  763. ;------------------------------
  764. BODY                dc.b 'BODY'
  765. sizeOfBODY        dc.l 0        ;add size of ATAK, RLSE, waveSize, and 80 bytes
  766.                                     ;(for each wave's header)
  767. ;for each wave, store these 80 bytes
  768. waveHeader:
  769. waveSize            dc.l 0
  770. midiSampNum        dc.w -1        ;inc for each wave
  771. loopType            dc.b 0        ;forward
  772. Itype                dc.b 0        ;unKnown
  773. samplePeriod    dc.l 55556    ;assume some default
  774. sampleRate        dc.l 18000    ;ditto
  775. loopStartPoint    dc.l 0
  776. loopEndPoint    dc.l 0
  777. rootNote            dc.b 0        ;set to the note # in middle of each octave (i.e.
  778.                                     ;note number = 6 for the lowest octave)
  779. velocityStart    dc.b 0
  780. velStartTable    ds.w 16
  781. sizeOfATAK        dc.l 0
  782. sizeOfRLSE        dc.l 0
  783. sizeOfFATK        dc.l 0
  784. sizeOfFRLS        dc.l 0
  785. sizeOfUserData    dc.l 0
  786. typeOfData        dc.w 0
  787.  
  788.  
  789. ATAKptr            dc.l 0
  790. RLSEptr            dc.l 0
  791.  
  792. ; For 10 waves
  793. SampleInfo0    dc.l 0 ;oneShot Start
  794.                 dc.l 0 ;byte offset to loopStart
  795.                 dc.l 0 ;byte offset to loopEnd (from wave beginning)
  796. SampleInfo1    dc.l 0
  797.                 dc.l 0
  798.                 dc.l 0
  799. SampleInfo2    dc.l 0
  800.                 dc.l 0
  801.                 dc.l 0
  802. SampleInfo3    dc.l 0
  803.                 dc.l 0
  804.                 dc.l 0
  805. SampleInfo4    dc.l 0
  806.                 dc.l 0
  807.                 dc.l 0
  808. SampleInfo5    dc.l 0
  809.                 dc.l 0
  810.                 dc.l 0
  811. SampleInfo6    dc.l 0
  812.                 dc.l 0
  813.                 dc.l 0
  814. SampleInfo7    dc.l 0
  815.                 dc.l 0
  816.                 dc.l 0
  817. SampleInfo8    dc.l 0
  818.                 dc.l 0
  819.                 dc.l 0
  820. SampleInfo9    dc.l 0
  821.                 dc.l 0
  822.                 dc.l 0
  823.  
  824.     XDEF    SAMPext,Same,NoMem,ReadErr,WriteErr,Not8SVX,Cancel,CantFind
  825.     XDEF    CantCreate,Quit,LibErr,Success,_BUFFER2,Directions
  826.  
  827. SAMPext            dc.b  '.SAMP',0
  828. Same                dc.b  'Would you like to save this SAMP file as',0
  829. NoMem                dc.b  'No memory for copy buffer.',0
  830. ReadErr            dc.b  'A read error occurred.',0
  831. WriteErr            dc.b  'A write error occurred.',0
  832. Not8SVX            dc.b  'Not an IFF 8SVX file',0
  833. Cancel            dc.b  'Conversion canceled',0
  834. CantFind            dc.b  'Can',$27,'t find the source file.',0
  835. CantCreate        dc.b  'Can',$27,'t create the destination file.',0
  836. WINTITLE            dc.b  '8SVX to SAMP Conversion  © 1989  dissidents',0
  837. Quit                dc.b  1
  838. LibErr            dc.b  'FileIO library failure',0
  839. Success            dc.b  '8SVX file successfully converted.',0
  840. InsTypeName        dc.b    'instype.library',0
  841.  
  842.  ; Use the following string area for Pathname buffer
  843. _BUFFER2:
  844. GfxName            dc.b  'graphics.library',0
  845. IntuitionName    dc.b  'intuition.library',0
  846. RequesterName    dc.b  'requester.library',0
  847. FileReqErr        dc.b  'Cannot find the "requester.library"',0
  848. IOerR                dc.b  'Cannot get a FileIO structure.',0
  849. FONTNAME            dc.b  'topaz.font',0
  850.                     ds.b  130
  851.  
  852. Click                dc.b  'Click mouse for file selection or CLOSEWINDOW.',0
  853.  
  854. Directions:
  855.  dc.b 'This program will convert an IFF 8SVX sampled sound file to the SAMP',0 
  856.  dc.b 'format. It requires the FileIO library in the libs drawer of your boot',0
  857.  dc.b 'disk. Click the mouse select button to begin filename selection, or',0
  858.  dc.b 'click on the CLOSE gadget to exit. Select the name of the 8SVX file to',0
  859.  dc.b 'be converted via the FileIO requester, then select OK. If the file is',0
  860.  dc.b 'successfully loaded and converted, you will be prompted to save the',0
  861.  dc.b 'new SAMP file in the same directory with a .SAMP extention added. You',0
  862.  dc.b 'may otherwise choose to enter a new name via the FileIO string gadgets.',0
  863.  dc.b 'If the SAMP file is successfully saved, a requester will indicate so.',0
  864.  dc.b 'This program was written by Jeff Glatt of dissidents.',0
  865.  
  866. SPACES:
  867.  dc.b '                                                                        ',0
  868.  
  869.